package com.khong.sale.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.khong.sale.R;
import com.khong.sale.entity.CustomerInfo;

public class CustomerListAdapter extends BaseAdapter {
	private Context mContext;
	private List<CustomerInfo> list;
	private LayoutInflater inflater;

	public CustomerListAdapter(Context cotext, List<CustomerInfo> list) {
		this.mContext = cotext;
		this.list = list;
		inflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.customer_list_item, null);
			holder = new Holder();
			holder.stateImg = (ImageView) convertView.findViewById(R.id.customer_icon);
			holder.shopName = (TextView) convertView.findViewById(R.id.customer_shop);
			holder.name = (TextView) convertView.findViewById(R.id.customer_contacter);
			holder.phone = (TextView) convertView.findViewById(R.id.customer_contact);
			holder.addr = (TextView) convertView.findViewById(R.id.customer_addr);
		} else {
			holder = (Holder) convertView.getTag();
		}
		
		 
		holder.shopName.setText( list.get(position).getShopName());
		holder.name.setText( list.get(position).getName());
		holder.phone.setText( list.get(position).getPhone());
		holder.addr.setText( list.get(position).getAddress());
		convertView.setTag(holder);
		return convertView;
	}

	class Holder {
		ImageView stateImg;
		TextView shopName;
		TextView name;
		TextView phone;
		TextView addr;
	}
}
